from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.html import format_html
from .models import CustomUser


@admin.register(CustomUser)
class CustomUserAdmin(UserAdmin):
    """基础的自定义用户Admin配置"""

    # 列表页显示的字段
    list_display = (
        'username', 'email', 'first_name', 'last_name',
        'is_vip', 'vip_level', 'phone', 'is_staff',
        'is_active', 'date_joined'
    )

    # 可用于过滤的字段
    list_filter = (
        'is_vip', 'vip_level', 'is_staff', 'is_superuser',
        'is_active', 'date_joined', 'groups'
    )

    # 可搜索的字段
    search_fields = ('username', 'first_name', 'last_name', 'email', 'phone')

    # 默认排序
    ordering = ('-date_joined',)

    # 在UserAdmin的基础上添加自定义字段
    fieldsets = UserAdmin.fieldsets + (
        ('扩展信息', {
            'fields': ('phone', 'avatar', 'birth_date', 'bio', 'is_vip', 'vip_level')
        }),
    )
